﻿using System.Globalization;
using System.Web.UI;

public class PageBase : Page
{
    private const string SESSION_KEY_LANGUAGE = "lang";

    protected override void InitializeCulture()
    {
        base.InitializeCulture();

        //If you would like to have DefaultLanguage changes to effect all users,
        // or when the session expires, the DefaultLanguage will be chosen, do this:
        // (better put in somewhere more GLOBAL so it will be called once)

        //Change language setting to user-chosen one
        if (Session[SESSION_KEY_LANGUAGE] != null)
        {
            ApplyNewLanguage((CultureInfo)Session[SESSION_KEY_LANGUAGE]);
        }
        else
        {
            LanguageManager.DefaultCulture = new CultureInfo("vi-VN");
            Session.Add(SESSION_KEY_LANGUAGE, LanguageManager.CurrentCulture);
        }
    }

    public void ApplyNewLanguage(CultureInfo culture)
    {
        LanguageManager.CurrentCulture = culture;
        //Keep current language in session
        Session.Add(SESSION_KEY_LANGUAGE, LanguageManager.CurrentCulture);
    }

    public void ApplyNewLanguageAndRefreshPage(CultureInfo culture)
    {
        ApplyNewLanguage(culture);
        Response.Redirect("/");
    }
    private bool lang;
    public bool Lang
    {
        get
        {
            if (Session["lang"] != null && Session["lang"].ToString().Equals("en-US"))
                return true;
            else
                return false;
        }
    }
}